package com.swanclouds.redfish.account.domain;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.swanclouds.model.account.AccountResource;
import com.swanclouds.redfish.common.redfish.MemberModel;

import java.util.List;
import java.util.Map;

/**
 * @author 张立强
 *
 */
public class AccountResourceModel implements AccountResource {
    @JsonProperty("Id")
    private String id;

    @JsonProperty("Name")
    private String name;

    @JsonProperty("@odata.id")
    private String dataId;

    @JsonProperty("@odata.context")
    private String context;

    @JsonProperty("@odata.type")
    private String type;

    @JsonProperty("ServiceEnabled")
    private Boolean serviceEnabled;

    @JsonProperty("Accounts")
    private MemberModel account;

    @JsonProperty("Roles")
    private MemberModel role;

    @JsonProperty("AccountLockoutThreshold")
    private Integer lockoutThreshold;

    @JsonProperty("AccountLockoutDuration")
    private Integer lockoutDuration;

    @JsonProperty("MinPasswordLength")
    private Integer minPasswordLength;

    @JsonProperty("MaxPasswordLength")
    private List<Integer> maxPasswordLength;

    @JsonProperty("Oem")
    private Map<String,Object> oem;

    /**
     * 用户服务资源的ID
     *
     * @return id
     */
    @Override
    public String getId() {
        return this.id;
    }

    /**
     * @return dataId
     */
    @Override
    public String getDataId() {
        return this.dataId;
    }

    /**
     * @return context
     */
    @Override
    public String getContext() {
        return this.context;
    }

    /**
     * @return type
     */
    @Override
    public String getType() {
        return this.type;
    }

    /**
     * 用户服务资源的名称
     *
     * @return name
     */
    @Override
    public String getName() {
        return this.name;
    }

    /**
     * 用户服务使能状态
     *
     * @return enabled
     */
    @Override
    public Boolean getServiceEnabled() {
        return this.serviceEnabled;
    }

    /**
     * 用户账户集合资源的访问路径
     *
     * @return ref
     */
    @Override
    public String accounts() {
        return account != null ? account.getDataId() : null;
    }

    /**
     * 用户角色集合资源的访问路径
     *
     * @return ref
     */
    @Override
    public String roles() {
        return role != null ? role.getDataId() : null;
    }

    /**
     * 允许用户密码输入错误次数，超过该次数，用户被锁定。0 表示不限制
     *
     * @return lockout
     */
    @Override
    public Integer getLockoutThreshold() {
        return this.lockoutThreshold;
    }

    /**
     * 用户登录失败后被锁定的时长。单位为秒，取值为10 的整数倍
     *
     * @return duration
     */
    @Override
    public Integer getLockoutDuration() {
        return this.lockoutDuration;
    }

    /**
     * 最小密码长度
     *
     * @return minLength
     */
    @Override
    public Integer getMinPasswordLength() {
        return this.minPasswordLength;
    }

    /**
     * 可供配置的最大密码长度
     *
     * @return maxLength
     */
    @Override
    public List<Integer> getMaxPasswordLength() {
        return this.maxPasswordLength;
    }

    /**
     * 厂商自定义字段
     *
     * @return oem
     */
    @Override
    public Map<String, Object> getOem() {
        return this.oem;
    }

    @Override
    public String toString() {
        ObjectMapper objectMapper = new ObjectMapper();
        try {
            return objectMapper.writeValueAsString(this);
        } catch (JsonProcessingException e) {
        }
        return "AccountResourceModel {" +
                "id='" + id + '\'' +
                ", name='" + name + '\'' +
                ", dataId='" + dataId + '\'' +
                ", context='" + context + '\'' +
                ", type='" + type + '\'' +
                ", serviceEnabled=" + serviceEnabled +
                ", account=" + account +
                ", role=" + role +
                ", lockoutThreshold=" + lockoutThreshold +
                ", lockoutDuration=" + lockoutDuration +
                ", minPasswordLength=" + minPasswordLength +
                ", maxPasswordLength=" + maxPasswordLength +
                ", oem=" + oem +
                '}';
    }
}
